package com.example.com.daervideo.activitys;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.Gravity;
import android.view.View;

import com.example.com.daervideo.BR;
import com.example.com.daervideo.R;
import com.example.com.daervideo.databinding.ActivityMainBinding;
import com.example.com.daervideo.fragments.MainFragment;
import com.example.com.daervideo.fragments.UserFragment;
import com.example.com.daervideo.popuwindow.PublishPpWindow;
import com.example.com.daervideo.vm.MainActivityViewModel;
import com.example.com.transcribeeditpublish.activity.LocalVideoImgActivity;
import com.example.com.transcribeeditpublish.activity.OutLinkActivity;
import com.example.com.transcribeeditpublish.activity.TCVideoRecordActivity;

import java.util.ArrayList;

import me.goldze.mvvmhabit.base.BaseActivity;

/**
 * Created by i7-1 on 2018/12/3.
 */
//
public class MainActivity extends BaseActivity<ActivityMainBinding, MainActivityViewModel> implements View.OnClickListener {


    private ArrayList<Fragment> list;
    private int currentUser = -1;
    private PublishPpWindow publishPpWindow;

    @Override
    public int initContentView() {
       /* //取消状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
        return R.layout.activity_main;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MainActivityViewModel initViewModel() {
        return new MainActivityViewModel(this);
    }

    @Override
    public void initData() {
        super.initData();
        list = new ArrayList<>();
        /*list.add(new CollectionFragmrnt());
        list.add(new MainFragment());*/
        list.add(new MainFragment());
        UserFragment userFragment = new UserFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("userType", 0);
        userFragment.setArguments(bundle);
        list.add(userFragment);
        getBinding().viewpager.setScanScroll(false);
        getBinding().viewpager.setAdapter(new HomeVPAdapter(getSupportFragmentManager()));
        getBinding().homeTab.setListener(this);
        publishPpWindow = new PublishPpWindow(this, this);
    }

    public int getCurrentUser() {
        return currentUser;
    }

    public void setCurrentUser(int currentUser) {
        this.currentUser = currentUser;
    }
    
    public void hideTab() {
        if (getBinding().homeTab.getVisibility() == View.VISIBLE)
            getBinding().homeTab.setVisibility(View.GONE);
    }

    public void showTab() {
        if (getBinding().homeTab.getVisibility() == View.GONE)
            getBinding().homeTab.setVisibility(View.VISIBLE);
    }

    private class HomeVPAdapter extends FragmentPagerAdapter {
        public HomeVPAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }


        @Override
        public int getCount() {
            return list.size();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //点击首页
            case R.id.home:
                getBinding().viewpager.setCurrentItem(0);
                break;
            //点击我的0
            case R.id.my:
                getBinding().viewpager.setCurrentItem(1);
                break;
            case R.id.publish:
                showPublishPpWindow();
                break;
            case R.id.transcribe:
                startActivity(new Intent(this, TCVideoRecordActivity.class));
                publishPpWindow.dismiss();
                break;
            case R.id.out_link:
                startActivity(new Intent(this, OutLinkActivity.class));
                publishPpWindow.dismiss();
                break;
            case R.id.pulish_local:
                startActivity(new Intent(this, LocalVideoImgActivity.class));
                publishPpWindow.dismiss();
                break;

        }
    }

    private void showPublishPpWindow() {
        publishPpWindow.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);
    }

}
